<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
// 路由简介：简单的说就是将用户的请求转发给相应的程序进行处理，建立URL与程序之间的映射

Route::get('/', function () {
    return view('hellow');
});

// 1.基本路由
Route::get('abc',function(){
    return 'get:this is abc route';
});
Route::post('abcd',function(){
    return 'post:this is abc route';
});
// 指定其中几个请求方式
Route::match(['post','get'],'routename',function(){
    return 'routename';
});
// 不指定请求方式
Route::any('any',function(){
    return 'any';
});
// 2.路由参数
Route::get('canshu-{id}',function($id){
    return 'id='.$id;
});
// 可选路由参数,需给默认值
Route::get('kexuan-{name?}',function($name=null){
    return 'kexuancanshu='.$name;
});
// 3.参数路由+正则验证
Route::get('kexuan2-{name?}',function($name=null){
    return 'kexuancanshu2='.$name;
})->where('name','[A-Za-z]+');
//多参数路由+正则验证
Route::get('kexuan3-{id}-{name?}',function($name=null,$id){
    return 'kexuancanshu3='.$name.'<br/>id='.$id;
})->where(['name'=>'[A-Za-z]+','id'=>'[0-9]+']);

//4. 路由别名，作用在控制器中可以用routeh('别名')函数生成别名对应的额url，场景：路由名改，使用别名会生成更改后的路由名URL
Route::get('bieming/bm',['as'=>'BM',function(){
    return route('BM');
}]);

// 5.群组路由,加了前缀之后那么这个群组路由就是前缀路由，需要在路由名前把前缀加上如下的user/order,需改成menber/user/order
//   群组路由除了可以设置前缀,还能设置中间件组,namespace,domain等等其他设置
Route::group(['prefix'=>'menber'],function(){
    Route::get('user/order',['as'=>'order',function(){
        return 'order';
    }]);
    Route::get('user/center',function(){
        return 'center';
    });
});

// 6.路由中输出视图
Route::get('view',function(){
    return view('hellow');
});

// 问题：路由怎么和控制器中的方法绑定？
// 怎样新建一个控制器（TestController.php）
// 路由和控制器中的方法绑定
Route::get('test/info','TestController@info');
Route::get('test/infos',['uses'=>'TestController@info']);
// 关联控制器后，路由的特性怎么用,（别名）
Route::get('test/infoss',[
    'uses'=>'TestController@info',
    'as'=>'testinfo'
    ]);
// 参数绑定+正则验证
 Route::get('test/infosss/{id}',[
    'uses'=>'TestController@infos',
    'as'=>'testinfos '
    ])->where('id','[0-9]+');

 Route::any('/user',['uses'=>'UserController@userinfo']);
 Route::any('/user1',['uses'=>'UserController@query']);
 Route::any('/testorm',['uses'=>'TestormController@testorm']);
 Route::any('blads',['uses'=>'BladsController@bladinfo']);
 Route::any('bladss',['as'=>'urls','uses'=>'BladsController@urlTest']);
 Route::get('form/a',['as'=>'form','uses'=>'FormController@formtest']);

// 中间件组，session
 Route::group(['middlware'=>['web']],function(){
    Route::any('session1',['as'=>'session','uses'=>'FormController@session1']);
    Route::any('session2',['as'=>'session2','uses'=>'FormController@session2']);
 });

// laravel表单
 Route::get('res',['as'=>'res','uses'=>'FormController@Response1']);

 // 中间件测试路由
 // 宣传页面
 Route::get('middle',['as'=>'middle','uses'=>'FormController@activity']);
 // 活动页面
 Route::group(['middleware'=>['activity']],function(){
     Route::get('middle1',['as'=>'middle1','uses'=>'FormController@activity1']);
     Route::get('middle2',['as'=>'middle2','uses'=>'FormController@activity2']);
 });

 Route::get('middle3',['as'=>'middle3','uses'=>'FormController@activity3']);

// 信息news路由
 Route::group(['middlware'=>['web']],function(){
     // 列表
     Route::get('news',['as'=>'news','uses'=>'NewsController@news']);
     // 新增
     Route::any('news/create',['as'=>'newscreate','uses'=>'NewsController@create']);
     Route::any('news/save',['as'=>'newssave','uses'=>'NewsController@save']);

     // 更新
     Route::any('news/update/{id}',['as'=>'newsupdate','uses'=>'NewsController@update'])->where('id','[0-9]+');
     Route::any('news/delete/{id}',['as'=>'newsdelete','uses'=>'NewsController@delete'])->where('id','[0-9]+');
 });

// 登录
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');

// 文件上传
Route::any('uploads', 'UploadsController@uploads')->name('uoloads');
